from django.db import models

# Create your models here.
from datetime import datetime




# 吐槽和吐槽的评论都属于吐槽的这张表
# 吐槽的parent_id为None,评论则有parent_id
class Spit(models.Model):
    content = models.CharField(max_length=200,verbose_name="吐槽内容")
    publishtime = models.DateTimeField(default=datetime.now(),verbose_name="发布日期")
    userid = models.IntegerField(null=True,verbose_name="发布人ID")
    nickname = models.CharField(default='匿名用户',max_length=20,verbose_name="发布人昵称")
    visits = models.BigIntegerField(default=0,verbose_name="浏览量")
    thumbup = models.BigIntegerField(default=0,verbose_name="点赞数")
    comment = models.BigIntegerField(default=0,verbose_name="回复数")
    avatar = models.CharField(null=True,max_length=500,verbose_name="用户头像")
    parent = models.ForeignKey('self', on_delete=models.SET_NULL, related_name='subs', null=True,verbose_name="上级ID")# 上级ID
    collected = models.BooleanField(default=False,verbose_name="是否收藏")
    hasthumbup = models.BooleanField(default=False,verbose_name="是否点赞")

    class Meta:
        db_table = 'tb_spit'
        verbose_name = '吐槽'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content
